import { http } from "@/utils/http";

/** 产品模型定义 */
export type ProductModel = {
  id: number;
  productKey: string;
  name: string;
  type: number;
  openStatus: number;
  remark: string;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取产品列表 */
export const getProductListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<ProductModel>>>(
    "get",
    "/product/page-list",
    { params: data }
  );
};

/** 新增产品 */
export const addProductApi = (data: Partial<ProductModel>) => {
  return http.request<Resp<null>>("post", "/product", { data });
};

/** 更新产品 */
export const updateProductApi = (id: number, data: Partial<ProductModel>) => {
  return http.request<Resp<null>>("put", `/product/${id}`, { data });
};

/** 更新产品状态 */
export const updateProductStatusApi = (id: number, openStatus: number) => {
  return http.request<Resp<null>>("patch", `/product/${id}/status`, {
    data: { openStatus }
  });
};

/** 删除产品 */
export const deleteProductApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/product/${id}`);
};

/** 根据ID获取产品详情 */
export const getProductByIdApi = (id: number) => {
  return http.request<Resp<{
    info: ProductModel
  }>>('get', '/product/getOne', {
    params: { id }
  });
};

/** 获取产品选项列表 */
export const getProductOptionsApi = (params?: { fieldKey?: string; fieldLabel?: string }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/product/getOptions', { params });
};
